<?php


namespace Tbf\Bundle\TbfBundle\Service;


use Doctrine\Common\Annotations\IndexedReader;

class AnnotationsReader extends IndexedReader{
    /**
     * @param $callable
     * @return array|null
     */
    function getCallableAnnotations($callable){
        if (is_array($callable)) {
            $r = new \ReflectionMethod($callable[0], $callable[1]);

            return $this->getMethodAnnotations($r);
        } elseif (is_object($callable) && !$callable instanceof \Closure) {
            $r = new \ReflectionObject($callable);
            $r = $r->getMethod('__invoke');

            return $this->getMethodAnnotations($r);
        } else {
            $r = new \ReflectionFunction($callable);

            return $this->getMethodAnnotations($r);
        }
    }
    function getCallableAnnotation($callable,$annotationName){
        if (is_array($callable)) {
            $r = new \ReflectionMethod($callable[0], $callable[1]);

            return $this->getMethodAnnotation($r,$annotationName);
        } elseif (is_object($callable) && !$callable instanceof \Closure) {
            $r = new \ReflectionObject($callable);
            $r = $r->getMethod('__invoke');

            return $this->getMethodAnnotation($r,$annotationName);
        } else {
            $r = new \ReflectionFunction($callable);

            return $this->getMethodAnnotation($r,$annotationName);
        }
    }
}